﻿using System.Linq;

namespace UniSender
{
    public class EmailErrorDescriptor
    {
        public virtual string Code { get; set; }
        
        public virtual string Message { get; set; }

        public virtual EmailError? Error { get; set; }

        public EmailErrorDescriptor()
        { }

        public EmailErrorDescriptor(Native.Error native)
        {
            Code = native.code;
            Message = native.error;
            try
            {
                Error = Utility.ParseEnum<EmailError?>(native.code);
            }
            catch { }
        }
    }

    public class EmailResult
    {
        public virtual int Index { get; set; }

        public virtual string Email { get; set; }

        public virtual string Id { get; set; }

        public virtual EmailErrorDescriptor[] Errors { get; set; }

        public EmailResult()
        { }

        public EmailResult(Native.EmailResult native)
        {
            Index = native.index;
            Email = native.email;
            Id = native.id;
            if (native.errors != null)
                Errors = native.errors.Select(e => new EmailErrorDescriptor(e)).ToArray();
        }
    }
}
